package com.holike.crm.fragment.analyze;

import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.holike.crm.R;
import com.holike.crm.base.BasePresenter;
import com.holike.crm.base.MyFragment;
import com.holike.crm.bean.DealerRankBean;
import com.holike.crm.util.Constants;
import com.holike.crm.util.DensityUtil;

/**
 * Created by wqj on 2018/6/1.
 * 经销商排行榜-经销商人员
 */

public class DealerRankPersonalFragment extends MyFragment {

    private int[] tvYourLocationId = new int[]{R.id.tv_dealer_rank_personal_your_location1, R.id.tv_dealer_rank_personal_your_location2, R.id.tv_dealer_rank_personal_your_location3, R.id.tv_dealer_rank_personal_your_location4, R.id.tv_dealer_rank_personal_your_location5};
    private int[] ivYourLocationId = new int[]{R.id.iv_dealer_rank_personal_your_location1, R.id.iv_dealer_rank_personal_your_location2, R.id.iv_dealer_rank_personal_your_location3, R.id.iv_dealer_rank_personal_your_location4, R.id.iv_dealer_rank_personal_your_location5};
    private int[] tvAreId = new int[]{R.id.tv_dealer_rank_personal_are1, R.id.tv_dealer_rank_personal_are2, R.id.tv_dealer_rank_personal_are3, R.id.tv_dealer_rank_personal_are4, R.id.tv_dealer_rank_personal_are5};

    @Override
    protected int getLayoutResourceId() {
        return R.layout.fragment_dealer_rank_personal;
    }

    @Override
    protected BasePresenter attachPresenter() {
        return null;
    }

    @Override
    protected void init() {
        super.init();
        setStatusBar();
        setTitle(getString(R.string.report_item11_title));
        Object obj = getExtra(Constants.DEALER_RANK);
        if (obj != null) {
            DealerRankBean dealerDataBean = (DealerRankBean) obj;
            if (dealerDataBean.getDealerData() != null) {
                DealerRankBean.DealerDataBean bean = dealerDataBean.getDealerData();
                setText(R.id.tv_dealer_rank_personal_city, bean.getCity());
                setText(R.id.tv_dealer_rank_personal_citycode, bean.getCityCode());
                setText(R.id.tv_dealer_rank_personal_after, bean.getAchievementAfter() + "万");
                setText(R.id.tv_dealer_rank_personal_rank, bean.getRankPre());
                setText(R.id.tv_dealer_rank_personal_count, "/" + bean.getRankAft());
                setText(R.id.tv_dealer_rank_personal_pre_city, bean.getPreCity());
                setText(R.id.tv_dealer_rank_personal_rank_no1, bean.getFirstThree().size() > 0 ? bean.getFirstThree().get(0).getCity() : "");
                setText(R.id.tv_dealer_rank_personal_rank_no2, bean.getFirstThree().size() > 1 ? bean.getFirstThree().get(1).getCity() : "");
                setText(R.id.tv_dealer_rank_personal_rank_no3, bean.getFirstThree().size() > 2 ? bean.getFirstThree().get(2).getCity() : "");
                for (int i = 0, size = bean.getRang().size(); i < size; i++) {
                    DealerRankBean.DealerDataBean.RangBean rangBean = bean.getRang().get(i);
                    ((TextView) mContentView.findViewById(tvAreId[i])).setText(rangBean.getName());
                    if (TextUtils.equals(rangBean.getIsIn(), "1")) {
                        mContentView.findViewById(tvYourLocationId[i]).setVisibility(View.VISIBLE);
                        ImageView imageView = mContentView.findViewById(ivYourLocationId[i]);
                        imageView.setVisibility(View.VISIBLE);
                        int dp16 = mContext.getResources().getDimensionPixelSize(R.dimen.dp_16);
                        int itemWidth = (DensityUtil.getScreenWidth(mContext) - dp16 * 2) / 5;
                        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
                        layoutParams.leftMargin = (int) ((itemWidth - dp16) * rangBean.getPosition());
                    }
                }
            }
        }
    }

    private void setText(int id, CharSequence text) {
        ((TextView) mContentView.findViewById(id)).setText(text);
    }
}
